package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Boxes;
import com.ruoyi.system.service.IBoxesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 宝箱信息Controller
 * 
 * @author ruoyi
 * @date 2025-01-17
 */
@RestController
@RequestMapping("/system/boxes")
public class BoxesController extends BaseController
{
    @Autowired
    private IBoxesService boxesService;

    /**
     * 查询宝箱信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:boxes:list')")
    @GetMapping("/list")
    public TableDataInfo list(Boxes boxes)
    {
        startPage();
        List<Boxes> list = boxesService.selectBoxesList(boxes);
        return getDataTable(list);
    }

    /**
     * 导出宝箱信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:boxes:export')")
    @Log(title = "宝箱信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Boxes boxes)
    {
        List<Boxes> list = boxesService.selectBoxesList(boxes);
        ExcelUtil<Boxes> util = new ExcelUtil<Boxes>(Boxes.class);
        util.exportExcel(response, list, "宝箱信息数据");
    }

    /**
     * 获取宝箱信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:boxes:query')")
    @GetMapping(value = "/{boxId}")
    public AjaxResult getInfo(@PathVariable("boxId") Long boxId)
    {
        return success(boxesService.selectBoxesByBoxId(boxId));
    }

    /**
     * 新增宝箱信息
     */
    @PreAuthorize("@ss.hasPermi('system:boxes:add')")
    @Log(title = "宝箱信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Boxes boxes)
    {
        return toAjax(boxesService.insertBoxes(boxes));
    }

    /**
     * 修改宝箱信息
     */
    @PreAuthorize("@ss.hasPermi('system:boxes:edit')")
    @Log(title = "宝箱信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Boxes boxes)
    {
        return toAjax(boxesService.updateBoxes(boxes));
    }

    /**
     * 删除宝箱信息
     */
    @PreAuthorize("@ss.hasPermi('system:boxes:remove')")
    @Log(title = "宝箱信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{boxIds}")
    public AjaxResult remove(@PathVariable Long[] boxIds)
    {
        return toAjax(boxesService.deleteBoxesByBoxIds(boxIds));
    }
}
